package com.woniuxy.order.controller;


import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.woniuxy.commons.Goods;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: 15489  <br/>
 * Date: 2022/3/25:11:43  <br/>
 * Description:
 */
@RestController
@RequestMapping("/order")
public class orderController {
    @Resource
    private RestTemplate restTemplate;
@GetMapping("/add")
@HystrixCommand(fallbackMethod = "abc")
    public String add(){
        String url="http://127.0.0.1:8080/goods/all";
//        参数一 ：请求的url
//          参数二：返回的数据类型
        List<Goods> data = restTemplate.getForObject(url, List.class);
//
        System.out.println(data);
        return "success";
    }
    public  String abc(){
    return  "abc";
    }





    @GetMapping("/find")
    public  Goods  find(){
    String url ="http://127.0.0.1:8080/goods/find/1001";
        Goods goods = restTemplate.getForObject(url, Goods.class);
        return goods;
    }
    @GetMapping("/add2")
    public  boolean  add2(){
        String url ="http://127.0.0.1:8080/goods/add";
        Goods goods=new Goods(1002,"手机",3213);
        Boolean result = restTemplate.postForObject(url, goods, boolean.class);
        return result;
    }
    @GetMapping("/updata")
    public  void updata(){
        String url ="http://127.0.0.1:8080/goods/updata";
        Goods goods=new Goods(1002,"手机",3213);
        restTemplate.put(url,goods); // 没有返回结果


    }
    @GetMapping("/del")
    public  void del(){
        String url ="http://127.0.0.1:8080/goods/del/1004";
        restTemplate.delete(url);
    }

//    测试集群
    @GetMapping("/port")
    public String port(){
//    集权环境下讲ip 端口替换成微服务的名字 （与eureka中的保持一致 大小一致）
        String url ="http://GOODS/port/get";
        String port=restTemplate.getForObject(url,String.class);

        return port;
    }

}
